package com.netty.future;

import io.netty.channel.DefaultEventLoopGroup;
import io.netty.channel.EventLoopGroup;
import io.netty.util.concurrent.DefaultPromise;
import io.netty.util.concurrent.Promise;

/**
 * @author xl-9527
 * @since 2025/8/2
 **/
public class NettyPromiseDemo {

    private final EventLoopGroup eventExecutors = new DefaultEventLoopGroup(1);

    public Promise<String> getMsg() {
        final Promise<String> promise = new DefaultPromise<>(eventExecutors.next());

        eventExecutors.next().execute(() -> {
            try {
                Thread.sleep(1000);
                promise.setSuccess("hello xl-9527");
            } catch (Exception e) {
                promise.setFailure(e);
            }
        });

        return promise;
    }
}
